using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for PersonalizationDao
/// </summary>
public class PersonalizationDao
{
    public PersonalizationDao() { }

    public void LoadPersonalizationBlobs(Personalization dto)
    {
        string proc = "sp_LoadPersonalizationBlobs";
        SqlParameter p1 = new SqlParameter("@UserID", SqlDbType.VarChar);
        SqlParameter p2 = new SqlParameter("@Path", SqlDbType.NVarChar);
        p1.Value = dto.UserID;
        p2.Value = dto.Path;

        DataSet ds = DbProvider.LoadData(proc, p1, p2);
        if (ds.Tables[0].Rows.Count > 0)
        {
            DataRow row = ds.Tables[0].Rows[0];
            if (row["PageSettings"] != DBNull.Value)
            {
                dto.PageSettings = (byte[])row["PageSettings"];
            }
        }
        ds.Dispose();
    }

    public void ResetPersonalizationBlob(Personalization dto)
    {
        string proc = "sp_ResetPersonalizationBlob";
        SqlCommand cmd = DbProvider.CreateCommand(proc);
        cmd.Parameters.Add("@UserID", SqlDbType.VarChar);
        cmd.Parameters.Add("@Path", SqlDbType.NVarChar);
        cmd.Parameters["@UserID"].Value = dto.UserID;
        cmd.Parameters["@Path"].Value = dto.Path;
        DbProvider.ExecCmd(cmd);
    }

    public void SavePersonalizationBlob(Personalization dto)
    {
        string proc = "sp_SavePersonalizationBlob";
        SqlCommand cmd = DbProvider.CreateCommand(proc);
        cmd.Parameters.Add("@UserID", SqlDbType.VarChar);
        cmd.Parameters.Add("@Path", SqlDbType.NVarChar);
        cmd.Parameters.Add("@PageSettings", SqlDbType.Image);
        cmd.Parameters["@UserID"].Value = dto.UserID;
        cmd.Parameters["@Path"].Value = dto.Path;
        cmd.Parameters["@PageSettings"].Value = dto.PageSettings;
        DbProvider.ExecCmd(cmd);
    }
}
